package com.wolfman.wolfchat.config;

import com.wolfman.wolfchat.interceptor.AuthenticationInterceptor;
import com.wolfman.wolfchat.interceptor.TokenInterceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

import javax.annotation.Resource;

/**
 * @Title
 * @Description
 * @Author WolfMan
 * @Date 2022/1/14 19:48
 * @Email 2370032534@qq.com
 */
@Configuration
public class WebMvcConfig extends WebMvcConfigurerAdapter {

    @Resource
    TokenInterceptor tokenInterceptor;

    @Resource
    AuthenticationInterceptor authenticationInterceptor;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {

        //1.加入的顺序就是拦截器执行的顺序，也可以使用order（）方法
        //2.按顺序执行所有拦截器的preHandle
        //3.所有的preHandle 执行完再执行全部postHandle 最后是postHandle
        registry.addInterceptor(tokenInterceptor)
                //添加拦截规则
                .addPathPatterns("/**").order(1);
        registry.addInterceptor(authenticationInterceptor)
                //添加拦截规则
                .addPathPatterns("/**").order(2);
    }

}
